<?php
/**
 * Create By: PhpStorm
 * User: niechenguang
 * File: WordLibrary.php
 * Date: 2017/1/2
 * Time: 23:13
 */
namespace app\api\model\dao;

use think\Model;
use think\Db;

class WordForbidden extends Model
{
    protected $table = 'word_forbidden';

    protected $pk = 'id';

    /**
     * 添加分词
     *
     * @param $arrInput
     * @return mixed
     */
    public function addWord($arrInput)
    {
        unset($arrInput[$this->pk]);

        $this->data($arrInput);
        $this->save();
        return $this->data[$this->pk];
    }

    /**
     * 添加分词
     *
     * @param $arrInput
     * @return mixed
     */
    public function addWordBatch($arrInput)
    {
        return $this->saveAll($arrInput);
    }

    /**
     * 删除分词
     *
     * @param $type
     * @param $obj_id
     * @return mixed
     */
    public function delWordByid($id)
    {
        $arrCond = [
            'id' => ['=', $id]
        ];

        $ret = Db::table($this->table)->where($arrCond)->delete();
        return $ret;
    }

    /**
     * 删除分词
     *
     * @param $type
     * @param $obj_id
     * @return mixed
     */
    public function delWordByWord($id)
    {
        $arrCond = [
            'id' => ['=', $id]
        ];

        $ret = Db::table($this->table)->where($arrCond)->delete();
        return $ret;
    }

    /**
     * 根据单词查找
     *
     * @param $word
     * @return array|false|\PDOStatement|string|\think\Collection
     */
    public function getByWord($word)
    {

        $arrCond = [
            'word' => ['like', $word . '%']
        ];

        $ret = Db::table($this->table)->where($arrCond)->select();
        return !empty($ret) ? $ret : [];
    }

    /**
     * 根据单词查找
     *
     * @param $word
     * @return array|false|\PDOStatement|string|\think\Collection
     */
    public function getAllWord()
    {
        $ret = Db::table($this->table)->select();
        return !empty($ret) ? $ret : [];
    }

}
